/*
 *
 * Global reducer
 *
 */

import { fromJS } from 'immutable';
import * as globalTypes from '../../constants/Global';

export const initialState = fromJS({
  loading: false,
  error: false
});

function globalReducer(state = initialState, action) {
  switch (action.type) {

    case globalTypes.LOAD_DATA:
      return state.set('loading',true)

    case globalTypes.LOAD_DATA_SUCCESS:
      return state.set('loading',false)

    case globalTypes.LOAD_DATA_ERROR:
      return state.set('loading',false)
            .set('error', action.payload.error)

    default:
      return state;
  }
}

export default globalReducer;
